import client from "@/lib/api/client"
import { useEffect, useState } from "react"
import Prism from "prismjs"
import "prismjs/themes/prism.css"

export default function TextPreview({ fileName }: { fileName: string }) {
  const [content, setContent] = useState<string>("")


  useEffect(() => {


    client.post("/api/text-preview/ReadTextFile", { fileName }).then(res => {
      setContent(res.data.content)
      Prism.highlightAll()
    }).catch(err => {
      console.error(err)
    })

  }, [])

  return <div className="select-text h-full overflow-auto">
    <pre className="">
      <code className="language-go">{content}</code>
    </pre>
  </div>
}

